package com.george.es.jwt;

import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

/**
 * <p>
 *  生成token
 * </p>
 *
 * @author GeorgeChan 2019/3/24 19:03
 * @version 1.0
 * @since jdk1.8
 */
public class CreateJwtTest1 {
    // 生成token，设置一分钟过期时间
    public static void main(String[] args) {
        JwtBuilder builder = Jwts.builder().setId("123")
                                           .setSubject("小智")
                                           .setIssuedAt(new Date())
                                           .signWith(SignatureAlgorithm.HS256, "george")
                                           .setExpiration(new Date(new Date().getTime() + 60000))
                                           .claim("role", "admin");
        // 打印taken
        System.out.println(builder.compact());
    }
}
